package com.lcfc.attend.controller;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lcfc.attend.entity.vo.ClockHistogram;
import com.lcfc.attend.entity.vo.ClockSituation;
import com.lcfc.attend.entity.vo.DutyMan;
import com.lcfc.attend.entity.vo.EmpStabilityVo;
import com.lcfc.attend.entity.vo.LineVo;
import com.lcfc.attend.entity.vo.MainChart;
import com.lcfc.attend.entity.vo.PunchReport;
import com.lcfc.attend.entity.vo.ResultData;
import com.lcfc.attend.service.ProjectService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/project")
public class ProjectController {
	
	@Autowired
	private ProjectService projectService;
	
	/**
	 * 首页人员持证情况
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "首页人员持证情况", notes = "首页人员持证情况")
    @PostMapping("/queryMainReport")
    public ResultData<PunchReport> queryMainReport(@ApiParam(value = "用户code") @RequestParam(required = false) String usercode) {
		List<PunchReport> list = projectService.queryMainReport(usercode);
		ResultData<PunchReport> result = new ResultData<PunchReport>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 获取首页打卡、在岗人数
	 * @param usercode
	 * @return
	 */
	@ApiOperation(value = "获取首页打卡、在岗人数", notes = "获取首页打卡、在岗人数")
    @PostMapping("/queryManNum")
    public ResultData<DutyMan> queryManNum(@ApiParam(value = "用户code") @RequestParam(required = false) String usercode) {
		DutyMan dutyMan = projectService.queryManNum(usercode);
		ResultData<DutyMan> result = new ResultData<DutyMan>();
		result.setCode(0);
		result.setCount(1);
		result.setMsg("操作成功");
		List<DutyMan> list = new ArrayList<DutyMan>();
		list.add(dutyMan);
		result.setData(list);
		return result;
	}
	/**
	 * 首页饼图
	 * @param usercode
	 * @return
	 */
	@ApiOperation(value = "首页饼图", notes = "首页饼图")
    @PostMapping("/queryMainChart")
    public ResultData<MainChart> queryMainChart(@ApiParam(value = "用户code") @RequestParam(required = false) String usercode) {
		List<MainChart> list = projectService.queryMainChart(usercode);
		
		ResultData<MainChart> result = new ResultData<MainChart>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 获取公司
	 * @param usercode
	 * @return
	 */
	@ApiOperation(value = "获取公司", notes = "获取公司")
    @PostMapping("/queryOffice")
    public ResultData<ClockSituation> queryOffice(@ApiParam(value = "用户code") @RequestParam(required = false) String usercode) {
		List<ClockSituation> list = projectService.queryOffice(usercode);
		ResultData<ClockSituation> result = new ResultData<ClockSituation>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 获取线路
	 * @param usercode
	 * @return
	 */
	@ApiOperation(value = "获取线路", notes = "获取线路")
    @PostMapping("/queryLines")
    public ResultData<LineVo> queryLines() {
		List<LineVo> list = projectService.queryLines();
		ResultData<LineVo> result = new ResultData<LineVo>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 获取安检公司打卡情况
	 * @param usercode
	 * @return
	 */
	@ApiOperation(value = "获取安检公司打卡情况", notes = "获取安检公司打卡情况")
    @PostMapping("/queryClockSituation")
    public ResultData<ClockHistogram> queryClockSituation(@ApiParam(value = "公司编码，多个以逗号隔开") @RequestParam(required = false) String officeCodes,
    		@ApiParam(value = "时间范围，周、月、季度、半年、年，分别以0,1,2,3,4代替") @RequestParam(required = false) String dateFlag,
    		@ApiParam(value = "考勤状态,分别以0,1,2,3,4代替,以逗号隔开") @RequestParam(required = false) String attenStates) {
		List<ClockHistogram> list = projectService.queryClockSituation(officeCodes,dateFlag,attenStates);
		ResultData<ClockHistogram> result = new ResultData<ClockHistogram>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 获取线路打卡情况
	 * @param officeCodes
	 * @param dateFlag
	 * @param attenStates
	 * @return
	 */
	@ApiOperation(value = "获取线路打卡情况", notes = "获取线路打卡情况")
    @PostMapping("/queryLineSituation")
    public ResultData<ClockHistogram> queryLineSituation(@ApiParam(value = "线路，多个以逗号隔开") @RequestParam(required = false) String lines,
    		@ApiParam(value = "时间范围，周、月、季度、半年、年，分别以0,1,2,3,4代替") @RequestParam(required = false) String dateFlag,
    		@ApiParam(value = "考勤状态,分别以0,1,2,3,4代替,以逗号隔开") @RequestParam(required = false) String attenStates) {
		List<ClockHistogram> list = projectService.queryLineSituation(lines,dateFlag,attenStates);
		ResultData<ClockHistogram> result = new ResultData<ClockHistogram>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
	/**
	 * 人员稳定性情况柱状图
	 * @param officeCodes
	 * @param lines
	 * @param dateFlag
	 * @param attenStates
	 * @return
	 */
	@ApiOperation(value = "人员稳定性情况柱状图", notes = "人员稳定性情况柱状图")
    @PostMapping("/queryEmpStability")
    public ResultData<EmpStabilityVo> queryEmpStability(@ApiParam(value = "公司编码，多个以逗号隔开") @RequestParam(required = true) String officeCodes,
    		@ApiParam(value = "时间范围，周、月、季度、半年、年，分别以0,1,2,3,4代替") @RequestParam(required = true) String dateFlag,
    		@ApiParam(value = "每月打卡天数") @RequestParam(required = true) String standardDay) {
		List<EmpStabilityVo> list = projectService.queryEmpStability(officeCodes,dateFlag,standardDay);
		ResultData<EmpStabilityVo> result = new ResultData<EmpStabilityVo>();
		result.setCode(0);
		result.setCount(list.size());
		result.setMsg("操作成功");
		result.setData(list);
		return result;
	}
}
